﻿@using Coralcode.Adapter.StatVisit.Entity.Domains
@using Coralcode.Utils.Basic
@using CoralNode.MvcClient.Helper
@{
    ViewBag.Title = "访客分析";
    ViewBag.PageModule = "visitor";
    ViewBag.CurrentPageUrl = "/m/statistic/visitor?orderfield=" + ViewBag.orderfield + "&orderDirection=" + ViewBag.orderDirection + "&";
    var order = ViewBag.orderDirection == "up" ? "class=order_up" : "class=order_down";
}
@Html.IncludePage("CoralAdmin/statistic", "_Left")
<!--content-->
<div id="pbody">
    <div class="extra">
        @Html.IncludePage("CoralAdmin/statistic", "DateSelection")
        <div class="main-box mt_2 mb_2">
            <div class="tab-visit clearfix">
                <a class="current" href="/m/statistic/visitor?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">地区分布</a>
                <a href="/m/statistic/visitorisp?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">网络运营商</a>
                <a href="/m/statistic/visitordevice?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">终端详情</a>
                <a href="/m/statistic/visitorisnew?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">新老访客</a>
                <a href="/m/statistic/visitorloyalty?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">忠诚度</a>
                <a href="/m/statistic/visitoractiveness?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">活跃度</a>
            </div>
            <div class="clearfix">
                <div class="table_visit">
                    <table width="100%" style="margin-top:2px;">
                        <thead>
                            <tr class="t_bg headRow">
                                <td width="20"></td>
                                <td><label class="radio"><input checked type="radio" name="locationLevel" value="province" />省份</label>
                                    <label class="radio ml_1"><input type="radio" name="locationLevel" value="city" />城市</label>
                                </td>
                                <td></td>
                                <td align="right">浏览次数（PV）|</td>
                                <td align="right"><div class="l"><a @if (ViewBag.orderField == "pvpercent" || string.IsNullOrEmpty(ViewBag.orderField)) {@String.Format(order)}else{@String.Format("class=order_none")} orderField="pvpercent"><i></i>占比</a></div></td>
                                <td align="right"><a @if (ViewBag.orderField == "uv"){@String.Format(order)}else{@String.Format("class=order_none")} orderField="uv"><i></i>独立访客(UV)</a></td>
                                <td align="right"><a @if (ViewBag.orderField == "ip"){@String.Format(order)}else{@String.Format("class=order_none")} orderField="ip"><i></i>IP</a></td>
                                <td align="right"><a @if (ViewBag.orderField == "newuv"){@String.Format(order)}else{@String.Format("class=order_none")} orderField="newuv"><i></i>新独立访客</a></td>
                                <td align="right"><a @if (ViewBag.orderField == "sc"){@String.Format(order)}else{@String.Format("class=order_none")} orderField="sc"><i></i>访问次数</a></td>
                                <td align="right"><a @if (ViewBag.orderField == "brate"){@String.Format(order)}else{@String.Format("class=order_none")} orderField="brate"><i></i>跳出率</a></td>
                                <td align="center">查看运营商</td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="count">
                                <td></td>
                                <td>全站总计</td>
                                <td></td>
                                <td align="right">@Model.PageView</td>
                                <td align="left">@MathUtil.RoundPercent(Model.PageViewPercent)%</td>
                                <td align="right">@Model.UniqueVisitor</td>
                                <td align="right">@Model.IpCount</td>
                                <td align="right">@Model.NewUniqueVisitor</td>
                                <td align="right">@Model.SessionCount</td>
                                <td align="right">@MathUtil.RoundPercent(Model.BounceRate)%</td>
                                <td align="center">-</td>
                            </tr>
                            @foreach (StatReportDomain report in ViewBag.ProvinceSummaryReports) {
                                <tr class="unfold_wrap @if(report.Equals(ViewBag.LastProvinceSummaryReports)){@String.Format("last")}">
                                    <td>
                                        @if (report.RefCityReports != null && report.RefCityReports.Count > 0) {
                                            <div class="unfold"><i class="ico ico_up"></i></div>
                                        }
                                    </td>
                                    <td>@report.StatName</td>
                                    <td align="center"><a class="ml_1-5" href="#"><i class="ico ico_visit_time"></i></a></td>
                                    <td align="right">@report.PageView</td>
                                    <td align="left">@MathUtil.RoundPercent(report.PageViewPercent)%</td>
                                    <td align="right">@report.UniqueVisitor</td>
                                    <td align="right">@report.IpCount</td>
                                    <td align="right">@report.NewUniqueVisitor</td>
                                    <td align="right">@report.SessionCount</td>
                                    <td align="right">@MathUtil.RoundPercent(report.BounceRate)%</td>
                                    <td align="center">
                                        @if (report.RefIspReports != null && report.RefIspReports.Count > 0) {
                                            <a class="color_green unfold_new" style="float: none;cursor: pointer">查看</a>
                                        }
                                    </td>
                                </tr>
                                if (report.RefCityReports != null && report.RefCityReports.Count > 0) {
                                    <tr class="unfold_cnt @if(report.Equals(ViewBag.LastProvinceSummaryReports)){@String.Format("last")}">
                                        <td colspan="11">
                                            <table width="100%">
                                                <tbody>
                                                    @foreach (StatReportDomain cityreport in report.RefCityReports) {
                                                        <tr class="extraTrs">
                                                            <td width="20" style="padding: 9px 10px;"></td>
                                                            <td style="padding: 9px 10px;">@cityreport.StatName</td>
                                                            <td style="padding: 9px 10px;"></td>
                                                            <td style="padding: 9px 10px;" align="right">@cityreport.PageView</td>
                                                            <td style="padding: 9px 10px;" align="left">@MathUtil.RoundPercent(cityreport.PageViewPercent)%</td>
                                                            <td style="padding: 9px 10px;" align="right">@cityreport.UniqueVisitor</td>
                                                            <td style="padding: 9px 10px;" align="right">@cityreport.IpCount</td>
                                                            <td style="padding: 9px 10px;" align="right">@cityreport.NewUniqueVisitor</td>
                                                            <td style="padding: 9px 10px;" align="right">@cityreport.SessionCount</td>
                                                            <td style="padding: 9px 10px;" align="right">@MathUtil.RoundPercent(cityreport.BounceRate)%</td>
                                                            <td style="padding: 9px 10px;" align="center">-</td>
                                                        </tr>
                                                    }
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                }
                                if (report.RefIspReports != null && report.RefIspReports.Count > 0){
                                    <tr class="unfold_cnt_new @if(report.Equals(ViewBag.LastProvinceSummaryReports)){@String.Format("last")}" style="display:none;background-color: #EDF0F3;">
                                        <td colspan="11">
                                            <table width="100%" class="table_visit">
                                                <tbody>
                                                    @foreach (StatReportDomain ispreport in report.RefIspReports) {
                                                        <tr class="extraTrs">
                                                            <td style="padding: 9px 10px;" width="20"></td>
                                                            <td style="padding: 9px 10px;">@ispreport.StatName</td>
                                                            <td style="padding: 9px 10px;"></td>
                                                            <td style="padding: 9px 10px;" align="right">@ispreport.PageView</td>
                                                            <td style="padding: 9px 10px;" align="left">@MathUtil.RoundPercent(ispreport.PageViewPercent)%</td>
                                                            <td style="padding: 9px 10px;" align="right">@ispreport.UniqueVisitor</td>
                                                            <td style="padding: 9px 10px;" align="right">@ispreport.IpCount</td>
                                                            <td style="padding: 9px 10px;" align="right">@ispreport.NewUniqueVisitor</td>
                                                            <td style="padding: 9px 10px;" align="right">@ispreport.SessionCount</td>
                                                            <td style="padding: 9px 10px;" align="right">@MathUtil.RoundPercent(ispreport.BounceRate)%</td>
                                                            <td style="padding: 9px 10px;" align="center">-</td>
                                                        </tr>
                                                    }
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div> 
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("[name='locationLevel']").click(function () {
            if ($(this).val()=="city") {
                window.location = "/m/statistic/visitorcity?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselect&orderfield=@ViewBag.orderfield&orderDirection=@ViewBag.orderDirection";
            }
        });
        $(".headRow a").css("cursor", "pointer").click(function () {
            var orderField = $(this).attr("orderField");
            var orderDirection = ($(this).hasClass("order_none") || $(this).hasClass("order_up"))?"down":"up";
            window.location = "/m/statistic/visitor?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselect&orderfield=" + orderField + "&orderDirection=" + orderDirection;
        });
        $(".unfold_new").click(function () {
            var parent = $(this).parents("tr.unfold_wrap");
            var unfoldbtn = parent.find(".unfold");
            if (parent.hasClass("unfold_wrap_curr")) {
                if (unfoldbtn.hasClass("unfold_down")) {
                    unfoldbtn.click();
                }
            }
            parent.toggleClass("unfold_wrap_curr");
            parent.nextUntil(".unfold_cnt_new").next().toggle();
        });
        $('.unfold').click(function () {
            var nexttr = $(this).parents("tr.unfold_wrap").next().next();
            if (nexttr.hasClass("unfold_cnt_new")) {
                nexttr.hide();
            }
        });
        $(".extraTrs").each(function () {
            $(this).find("td").each(function (i) {
                $(this).width($(".headRow td").eq(i).width());
            });
        });
    });
</script>